package com.lzw.mapper.admin;

import com.lzw.pojo.DormitoryAdmin;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DormitoryAdminManagementMapper {

    // 查询公寓管理员列表
    List<DormitoryAdmin> listDormitoryAdmins(@Param("name") String name, @Param("gender") String gender, @Param("dormitoryBuildingId")Integer dormitoryBuildingId);

    //检查名字是否重复
    @Select("SELECT COUNT(*) FROM dormitorymanagement.dormitoryadmin WHERE name = #{name}")
    int countByName(String name);

    //检查用户名是否重复
    @Select("SELECT COUNT(*) FROM dormitorymanagement.dormitoryadmin WHERE username = #{username}")
    int countByUsername(String username);

    //检查用户电话号码
    @Select("SELECT COUNT(*) FROM dormitorymanagement.dormitoryadmin WHERE phone = #{phone}")
    int countByPhone(String phone);

    // 添加公寓管理员
    @Insert("INSERT INTO dormitorymanagement.dormitoryadmin (name, username, password, gender, phone, email, dormitory_building_id) " +
            "VALUES (#{name}, #{username}, #{password}, #{gender}, #{phone}, #{email}, #{dormitoryBuildingId})")
    void addDormitoryAdmin(DormitoryAdmin dormitoryAdmin);

    // 删除公寓管理员
    void deleteDormitoryAdmin(@Param("ids") List<Integer> ids);

    // 更新公寓管理员信息
    void updateDormitoryAdmin(DormitoryAdmin dormitoryAdmin);

    // 根据ID查询公寓管理员信息
    @Select("SELECT * FROM dormitorymanagement.dormitoryadmin WHERE admin_id = #{id}")
    DormitoryAdmin getDormitoryAdminById(int id);

    @Select("SELECT * FROM dormitorymanagement.dormitoryadmin")
    List<DormitoryAdmin> listAll();
}
